package sf.database.dialect.db;

import sf.database.dialect.DBDialect;
import sf.database.dialect.Keywords;
import sf.database.meta.TableMapping;
import sf.database.support.DBMS;
import sf.jooq.JooqSupportDatabase;
import sf.querydsl.QueryDSLSupportDatabase;

import java.sql.Connection;

/**
 * Derby
 */
public class DerbyDialect extends DBDialect {

    public DerbyDialect() {
        this.keywords.addAll(Keywords.DERBY);
    }

    @Override
    public String getDefaultSchema() {
        return "APP";
    }

    @Override
    public String getName() {
        return DBMS.derby.name();
    }

    @Override
    public int getNumber() {
        return DBMS.derby.getNumber();
    }

    @Override
    public String getHibernateDialect() {
        return null;
    }

    @Override
    public String sqlTableDrop(String table) {
        return null;
    }

    @Override
    public String sqlTableRename(String oldName, String newName) {
        return null;
    }

    @Override
    public String sqlColumnRename(String table, String oldColumnName, String newColumnName) {
        return null;
    }

    @Override
    public String sqlColumnAdd(String table, String column_definition, String column_position) {
        return null;
    }

    @Override
    public String sqlColumnModify(String table, String column_definition, String column_position) {
        return null;
    }

    @Override
    public String sqlColumnDrop(String table, String column) {
        return null;
    }

    @Override
    public StringBuilder sqlPageList(StringBuilder sql, long offset, int limit) {
        long pageEnd = offset + limit - 1;
        sql.insert(0, "select * from ( select t.*, row_number() over () as rn from ( ");
        sql.append(" ) t ) as tmp where rn between ");
        sql.append(offset).append(" and ").append(pageEnd);
        return sql;
    }

    @Override
    public boolean createEntity(Connection conn, TableMapping en) {
        return false;
    }

    @Override
    public String uniqueSql(String tableName, String name, String[] columnNames) {
        return null;
    }

    @Override
    public String getQueryDslDialect() {
        return QueryDSLSupportDatabase.Derby;
    }

    @Override
    public String getJooqDialect() {
        return JooqSupportDatabase.DERBY;
    }
}
